package ar.com.ford.it.fullEconomics.persistence.dao;

import java.io.InputStream;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import com.ford.it.logging.ILogger;
import com.ford.it.logging.LogFactory;
import com.ford.it.persistence.PersistenceConfigurationException;
import com.ford.it.persistence.PersistenceHelper;
import com.ford.it.properties.PropertyManager;


public class JndiInitializeBDF implements ServletContextListener {
    private static final String CLASS_NAME = JndiInitializeBDF.class.getName();

    private static ILogger log = LogFactory.getInstance().getLogger(CLASS_NAME);
    private static PropertyManager propertyManager;
    private static PropertyManager propertyCommonManager;
    private String jobRunningServer = null;

    public void contextDestroyed(ServletContextEvent arg0) {
    }

    public void contextInitialized(ServletContextEvent arg0) {
       propertyManager = PropertyManager.getInstance();
       
        try {
            
        	InputStream stream = Dao.class.getResourceAsStream("/resources/persistence-config.xml");
            propertyManager.load(stream);
            
        } catch (Exception e) {
            e.printStackTrace();
        }

    }
    
    public static PropertyManager getInstance()
    {
        return propertyManager;
    }

    public void init() throws PersistenceConfigurationException {
        try {
            System.out.println("Before Persistence");
            
            PersistenceHelper.initialize("resources/persistence-config.xml");

            System.out.println("After Persistence");
            
        } catch (Exception e) {
            System.out.println("the persistence Fullee can't initialize");
            e.printStackTrace();
        }

        this.log = LogFactory.getInstance().getLogger(this.getClass().getName());
    }
   
}
